<?php
    /**
     *  
     */
    class BlogArticleText extends BaseModel
    {

        protected $_id;
        protected $_userId;
        protected $_blogId;
        protected $_articleId;
        protected $_topic;
        protected $_text;
        protected $_normalizedSearch;

        /**
         *  讀取資料表而產生, 請視同cache, 任何情況下皆不可更動該產生的內容
         *  @return Array()
         */
        public static function getTableDefinition()
        {
        }

        /**
         *  經資料表傳至程式中時所對應的 method 資訊
         *  @return Array()
         */
        public static function getTableFields()
        {
            return Array(
                "id"                    => "getId",
                "user_id"               => "getUserId",
                "blog_id"               => "getBlogId",
                "article_id"            => "getArticleId",
                "topic"                 => "getTopic",
                "text"                  => "getText",
                "normalized_search"     => "getNormalizedSearch"
            );
        }

        /**
         *  reset to default value model
         *  @return Array()
         */
        public function resetValue() {
            $this->__sleep();
            $this->setId               ( -1 );
            $this->setUserId           ( NULL );
            $this->setBlogId           ( NULL );
            $this->setArticleId        ( NULL );
            $this->setTopic            ( NULL );
            $this->setText             ( NULL );
            $this->setNormalizedSearch ( NULL );
        }

        /**
         *  validate model data
         *  @return messages Array()
         */
        public function validate()
        {
            $validateInfo = parent::validate();

            if( null===$this->getUserId() ) {
                $validateInfo['userId']['message'] = '不能空值';
            }
            if( null===$this->getBlogId() ) {
                $validateInfo['blogId']['message'] = '不能空值';
            }
            if( null===$this->getArticleId() ) {
                $validateInfo['articleId']['message'] = '不能空值';
            }
            if( !$this->getTopic() ) {
                $validateInfo['topic']['message'] = '不能空值';
            }
            if( !$this->getText() ) {
                $validateInfo['text']['message'] = '不能空值';
            }

            return $validateInfo;
        }

        /**
         *  filter model data
         */
        public function filter()
        {
            $this->setUserId           ( (int) $this->getUserId() );
            $this->setBlogId           ( (int) $this->getBlogId() );
            $this->setArticleId        ( (int) $this->getArticleId() );
            $this->setTopic            ( trim(strip_tags( $this->getTopic()                )) );
            $this->setText             ( trim( $this->getText() ) );
            $this->setNormalizedSearch ( trim(strip_tags( $this->getNormalizedSearch()     )) );
        }

        /* ------------------------------------------------------------------------------------------------------------------------
            basic method 
        ------------------------------------------------------------------------------------------------------------------------ */

        /**
         *  get UserId 
         *  @return int
         */
        public function getUserId()
        {
            return $this->_userId;
        }
        /**
         *  set UserId
         */
        public function setUserId( $userId )
        {
            $this->_userId = (int) $userId;
        }

        /**
         *  get BlogId 
         *  @return int
         */
        public function getBlogId()
        {
            return $this->_blogId;
        }
        /**
         *  set BlogId
         */
        public function setBlogId( $blogId )
        {
            $this->_blogId = (int) $blogId;
        }

        /**
         *  get ArticleId 
         *  @return int
         */
        public function getArticleId()
        {
            return $this->_articleId;
        }
        /**
         *  set ArticleId
         */
        public function setArticleId( $articleId )
        {
            $this->_articleId = (int) $articleId;
        }

        /**
         *  get Topic
         *  @return string
         */
        public function getTopic()
        {
            return $this->_topic;
        }
        /**
         *  set Topic
         */
        public function setTopic( $topic )
        {
            $this->_topic = trim($topic);
        }

        /**
         *  get Text
         *  @return string
         */
        public function getText()
        {
            return $this->_text;
        }
        /**
         *  set Text
         */
        public function setText( $text )
        {
            $this->_text = trim($text);
        }

        /**
         *  get NormalizedSearch
         *  @return string
         */
        public function getNormalizedSearch()
        {
            return $this->_normalizedSearch;
        }
        /**
         *  set NormalizedSearch
         */
        public function setNormalizedSearch( $normalizedSearch )
        {
            $this->_normalizedSearch = trim($normalizedSearch);
        }


        /* ------------------------------------------------------------------------------------------------------------------------
            extends
        ------------------------------------------------------------------------------------------------------------------------ */
        /**
         *  clear extends information
         */
        public function __sleep()
        {
            $this->_blog = null;
            return parent::__sleep();
        }

        /**
         *  get blog model
         *  @param isSave 是否儲存取得的物件
         *  @return object
         */
        public function getBlog( $isSave=true )
        {
            if( !$isSave ) {
                $this->_blog = null;
            }
            if( $this->_blog ) {
                return $this->_blog;
            }

            $blogs = new Blogs();
            $blog = $blogs->getBlog( $this->getBlogId() );

            if( $isSave ) {
                $this->_blog = $blog;
            }
            return $blog;
        }

    }

